import GlobalData from "./GlobalData";

// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class itemmove extends cc.Component {


    start () {
        //y高度范围 -200~-800, x范围 1700~1900
        // let y = Math.random() * 600 + 150, x=Math.random() * 200 + 1700
        // this.node.y = -y;
        // this.node.x = 2300;

      
        // cc.tween(item).repeatForever(status).start();  
    }
    init(){
        let posx = this.node.x;
        let time = Math.floor(Math.random() * 10 + 15);

        let delay_time =  Math.random() * 2000 + 1000;
        cc.tween( this.node).to((posx+2300)/100, { x: -2300 }).call(()=>{
           
            this.repartmove();   

        }).start(),this;
        
    }

    repartmove(){

        let y = Math.random() * 600 + 150, x=Math.random() * 200 + 1700
        this.node.y = -y;
        this.node.x = 2300;

        let delay_time =  Math.random() * 2000 + 1000;
    
        cc.tween( this.node ).to(50, { x: -2300 }).call(()=>{
            
            this.repartmove();        

        }).start(),this;
    }

    clickEvent(){

        this.node.active = false;

        //id 跟 title 自定义属性
        let data = {id: this.node.id, title:this.node.title};
        GlobalData.gameData.push(data);

        GlobalData.sum++;

        console.log(GlobalData.gameData);
        console.log(GlobalData.sum);
    }

    // update (dt) {}
}
